package com.qh.resourcehub.program.wifi.controller;

import com.qh.resourcehub.program.dto.WifiDto;
import com.qh.resourcehub.program.vo.WifiVo;
import com.qh.resourcehub.program.wifi.service.WifiService;
import com.qh.resourcehub.utils.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//2.青海省气象部门终端入网和IP地址申请/变更表
//（ip申请、终端入网、wifi申请） 02
@RestController
@RequestMapping("/wifiApply")
public class WifiApplyController {
    @Autowired
    private WifiService wifiService;
    /*
     * @Description:
     * @param 查询申请信息
     * @return
     * @Author: Y6
     * @Date: 2025/4/18 14:19
     */
    @PostMapping("/queryWifiData")
    public ApiResponse queryWifiData(@RequestBody WifiDto wifiDto) {
        try {
            List<WifiVo> data = wifiService.queryWifiData(wifiDto);
            if (data.size()>0){
                return ApiResponse.succeed(data);
            }else {
                return ApiResponse.succeedNoData();
            }
        }catch (Exception e){
            return ApiResponse.succeedRequestNo();
        }
    }

    /**
     * IP申请新增
     * @param
     * @return
     */
    @PostMapping("/ApplicationSave")
    public ApiResponse ApplicationSave(@RequestBody WifiDto wifiDto) {
        try {
            int i = wifiService.ApplicationSave(wifiDto);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            return ApiResponse.succeedRequestNo();
        }
    }

    /**
     * IP申请新增
     * @param
     * @return
     */
    @PostMapping("/ApplicationUpdata")
    public ApiResponse ApplicationUpdata(@RequestBody WifiDto wifiDto) {
        try {
            int i = wifiService.ApplicationUpdata(wifiDto);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            return ApiResponse.succeedRequestNo();
        }
    }
    /**
     * IP申请删除
     * @param
     * @return
     */
    @PostMapping("/Applicationdel")
    public ApiResponse Applicationdel(@RequestBody WifiDto wifiDto) {
        try {
            int i = wifiService.Applicationdel(wifiDto);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            return ApiResponse.succeedRequestNo();
        }
    }

    /**examine
     * 虚拟资源申请提交
     * @param
     * @return
     */
    @PostMapping("/ApplicationSubmit")
    public ApiResponse ApplicationSubmit(@RequestBody WifiDto wifiDto) {
        try {
            int i = wifiService.ApplicationSubmit(wifiDto);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            return ApiResponse.succeedRequestNo();
        }
    }

    /**
     * 虚拟资源申请撤回
     * @param
     * @return
     */
    @PostMapping("/ApplicationWithdraw")
    public ApiResponse ApplicationWithdraw(@RequestBody WifiDto wifiDto) {
        try {
            int i = wifiService.ApplicationWithdraw(wifiDto);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            e.printStackTrace(); // 打印完整堆栈信息
            return ApiResponse.succeedRequestErr("操作失败: " + e.getMessage()); // 返回详细错误信息
        }
    }
}
